/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MobileNode;

import java.util.logging.Level;
import java.util.logging.Logger;
import messages.RegistrationRequest;

/**
 *
 * @author Rente
 */
public class SolicitationThread extends Thread{

    MobileNode mn;

    public SolicitationThread(MobileNode mn) {
        this.mn = mn;
        this.start();
    }

    @Override
    public void run() {

        RegistrationRequest rr = new RegistrationRequest();
        rr.setIpAddress(mn.getIpAddress());
        rr.setMACAddress(mn.getMACAddress());
        rr.setCareOfAddress(mn.getCareOfAddress());
        rr.setIpHomeAddress(mn.getHomeAddress());

        while (true) {
             if(mn.isHasSignal()){
                     try {
                if (!mn.isConnected()) {
                    if (mn.isHome()) {
                        mn.sendMessage("localhost", rr.toString(), 49552);
                    } else if (!mn.isHome()) {
                        mn.sendMessage("localhost", rr.toString(), 49553);
                    }
                }
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(SolicitationThread.class.getName()).log(Level.SEVERE, null, ex);
            }}
        }



    }
}
